﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Components;
using Controls;
using UI.Lib.Factory;
using UI.Lib;

namespace UI.SellOrder
{
    public partial class FrmOrd3a02Medit : UI.ParentForm.BaseMedit
    {
        public FrmOrd3a02Medit(string modulecode, string action, string text, string key, double ordamt, string sellerid, string comcode)
            : base(modulecode, action)
        {
            InitializeComponent();

            this.Text = text;
            this.Key = key;
            tspBtnAdd.Visible = false;
            tspBtnDel.Visible = false;
            tspSave.Visible = false;

            //重置窗口大小
            this.Size = new Size(600, 500);

            if (!string.IsNullOrEmpty(key)) //审核，数据来源于数据库
            {
                LoadData();
            }
            else //模拟费用计算
            {
                this.tbSummary.SetValue("ordamt", ordamt);

                //加载明细数据
                DataTable data = CommonHelper.Entity.ExecFun("getbas4a01list",
                    new KeyValuePair<string, object>("@a", comcode),
                    new KeyValuePair<string, object>("@b", sellerid));

                if (data == null || data.Rows.Count == 0) return;

                DataGridViewRow dgr = null;
                DataGridViewRow nRow = null;
                double taxagio = 0;
                double sumagio = 0;
                foreach (DataRow dr in data.Rows)
                {
                    dgr = new DataGridViewRow();
                    dgr.CreateCells(this.dgvDtl);

                    dgvDtl.Rows.Add(dgr);
                    nRow = dgvDtl.Rows[dgvDtl.Rows.Count - 1];

                    //填充值
                    UIHelper.FillDataGridViewRowFromDataRow(dr, nRow);

                    taxagio = Validation.ToDouble(dr["taxpct"]) * ordamt;
                    sumagio += taxagio;
                    nRow.Cells["agio"].Value = taxagio;
                }

                this.tbSummary.SetValue("agioamt", sumagio);
            }
        }

        //加载修改数据
        private void LoadData()
        {
            base.LoadEditData(null, string.Format(" listid ='{0}' ", this.Key));
            base.LoadDtlData(null, string.Format(" plistid ='{0}' ", this.Key));
        }
    }
}
